// pages/news-list/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    caselist: [],
    CurrentPage: 1,
    newstypeids: "",
    loadingMoreHidden: false
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    var newstypeid = options.newstypeid
    this.setData({
      newstypeids: newstypeid
    })
    this.showList(newstypeid)
  },
  //跳转文章详情
  toArtclelist: function (e) {
    console.log("文章详情")
    console.log(e)
    var newsid = e.currentTarget.dataset.newsid
    wx.navigateTo({
      url: '/pages/news-details/index?newsid=' + newsid,
    })
  },
  // 加载更多
  loadMore: function (e) {
    var that = this;
    if (!
    that.data.loadingMoreHidden) return;
    var currPage = that.data.CurrentPage;
    that.setData({
      CurrentPage: currPage + 1
    })
    that.showList(that.data.newstypeids);
  },
  //新闻列表
  showList: function (newstypeid){
    var that = this;
    wx.request({
      url: app.globalData.host + '/api/news/NewsList?newstitle=&newstypeid=' + newstypeid + '&storeid=' + app.globalData.storeId,
      data: {
        pageNumber: that.data.CurrentPage,
        pageSize: 10
      },
      success: function (res) {
        console.log("新闻列表")
        console.log(res)
        var caseArry = [];
        var NewsList = res.data.Data.NewsList
        var name = res.data.Data.NewsList[0].name
        wx.setNavigationBarTitle({
          title:name
        })
        for (var i = 0; i < NewsList.length; i++) {
          var f = NewsList[i];
          f.showimg = 'http://static.711688.net.cn/upload/news/' + f.showimg;
          f.title = f.title;
          f.newstypeid = f.newstypeid;
          f.addtime = f.addtime
          f.newsid = f.newsid
          caseArry.push(f);
        }
        if (that.data.CurrentPage != 1) {
          var preGoods = that.data.caselist
          caseArry = preGoods.concat(caseArry);
        }
        that.setData({
          caselist: caseArry,
          loadingMoreHidden: res.data.Data.PageModel.HasNextPage
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})